<template>
  <!-- 拆分 -->
  <el-dialog
    title="拆分"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :visible="splitVisible"
    @close="close"
    @open="open"
    class="main_dialog dialog1200"
  >
    <div class="dialog-body">
      <div class="main_ti">
        <el-tabs v-model="activeName">
          <el-tab-pane label="按商品" name="1">
            <goods-split
              :orderId="orderId" 
              @close="close"
              ref="goodSplit"
            >
            </goods-split>
          </el-tab-pane>
          <el-tab-pane label="按分类" name="2">
            <category-split 
              :orderId="orderId" 
              @close="close"
              ref="categorySplit"
            ></category-split>
          </el-tab-pane>
        </el-tabs>
      </div>
      
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit" v-repeatClick>确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import goodsSplit from "./goods_split.vue";
import categorySplit from "./category_split.vue";
export default {
  props: {
    splitVisible: {
      type: Boolean,
      default: false,
    },
    orderId: {
      type: [String,Number],
      default: "",
    },
  },
  components: { goodsSplit, categorySplit },
  data() {
    return {
      activeName: "1",
    };
  },
  methods: {
    // dialog打开的回调
    open() {
      this.$nextTick(()=> {
        this.$refs.goodSplit.getData();
        this.$refs.categorySplit.getData();
      });
    },
    // 取消/关闭
    close() {
      this.activeName = "1";
      this.$refs.goodSplit.resetData();
      this.$refs.categorySplit.resetData();
      this.$emit("update:splitVisible", false);
      this.$emit("close");
    },
    // 确定
    submit() {
      if(this.activeName==="1") {
        this.$refs.goodSplit.split();
      } else {
        this.$refs.categorySplit.split();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog-body {
  padding: 0 20px 15px;
}
.dialog1200 {
  /deep/.el-dialog {
    width: 1200px !important;
    position: relative !important;
    margin-top: 15vh !important;
  }
}
</style>